home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / web / fweb / fweb-1.40 / demos / macros.hweb < prev    next >
Text File  |  1993-10-29  |  2KB  |  58 lines

  1. @ Here is a more complete demo of \.{WEB} macro expansions. See the user
  2. manual for discussion of stringizing and token-pasting.
  3.  
  4. @m P(s) #s = s. /* Display macro and its result. Uses stringize operation. */
  5.  
  6. @m _A /* A null macro. */
  7. @m _B 2 /* A simple macro. */
  8. @m _C a + b + c /* Slightly more complicated, but no macros on rhs. */
  9. @m _C1 (_A)*(_B)*(_C) /* Macros on rhs. */
  10.  
  11. @m _D(x) (x)**9 /* Function macro. */
  12. @m _E(x,y) _B*(x)*(y) /* Two arguments, and a macro. */
  13.  
  14. @m VAR(i,j) var##i_##j /* Token pasting. */
  15. @m RECURSE(a,b) a##b(a,b) /* ANSI's example of possible recursion. */
  16. @m TRIPLE(a,b,c) a##b##c(a,b,c,a##b,a##c,b##c) /* Advanced token pasting. */
  17.  
  18. /* Recursion through several levels. */
  19. @m _R _W
  20. @m _W _X
  21. @m _X _R
  22.  
  23. @m _R1(i) _W##i(i) + ar
  24. @m _W1(i) _X##i(i) + _W1(i) + aw
  25. @m _X1(i) _R##i(i) + _X1(i) + ax
  26.  
  27. @a
  28.  /* OBJECT MACROS. */
  29.         P(_A) /* Null */
  30.         P(_B) /* Simple */
  31.         P(_C) /* Ordinary replacement. */
  32.         P(_C1) /* Macros on rhs. */
  33.  
  34.  /* FUNCTION MACROS. */
  35.         P(_D(x)) /* Basic form of function macro. */
  36.         P(_D(2)) /* Evaluation of the macro. */
  37.         P(_D(_B)) /* Macro argument as parameter. */
  38.         P(_D(_D(_C1))) /* Recursion. */
  39.  
  40.  /* SEVERAL ARGUMENTS. */
  41.         P(_E(x,y)) /* Basic form. */
  42.         P(_E(2,3)) /* Evaluation. */
  43.         P(_E(_D(_B),_C)) /* Macros as parameters. */
  44.         P(F(_A,_B,_E(_D(_B),_A))) /* Complicated. */
  45.  
  46.  /* TOKEN PASTING. */
  47.         P(VAR(1,2))
  48.         P(TRIPLE(a,_C,1))
  49.  
  50.  /* RECURSION. */
  51.         P(RECURSE(RE,CURSE)) /* Recursion. */
  52. @#if 0
  53.         P(RECURSE(RECURSE,RECURSE)) /* More recursion; invalid form. */
  54. @#endif
  55.  
  56.         P(_R) /* Recursion through several levels. */
  57.         P(_R1(1))
  58.